function goGame(is_confirm) {
	if(typeof(is_confirm) == 'undefined') is_confirm = false;
	
	if(!isShowGame) {
		isShowGame = true;
		jQuery('#flashcontainer').css('top', ( jQuery('#header').height() - 6 ) + 'px');
		jQuery('#boxes').html('').css('height', '0px');
		jQuery(document).trigger('close.facebox');
		jQuery('#wrapper').css('height', jQuery('#flashcontainer').height() < 610 ? '610px' : jQuery('#flashcontainer').height() + 'px');
		jQuery('#btn_gohome').parent().addClass("c").siblings().removeClass("c");
	}
	
	log('goGame', [isShowGame, jQuery('#header').height()]);
}

function goInvite(is_emcpt) {
	if(typeof(is_emcpt) == 'undefined') is_emcpt = 0;
	var fs = [];
	jQuery.each(f, function(i, v){
		if(1 == v.is_apped) fs.push(v.uid);
	});
	jQuery('#boxes').html('');
	
	log('goInvite', fs);
	
	showContain(
		'showinvite',
		{	},
		function() {
			if (!fbloaded) {
				jQuery('#serverFbmlContainer').html('系統出現異常.');
			}
			
			jQuery('#hidden_iframe').load(function(){
				
				jQuery('#hidden_iframe').unbind('load');
				jQuery('#facebox .content').html('發送邀請成功, 請<a href="#" onclick="jQuery(document).trigger(\'close.facebox\');">關閉</a>.');
				facebox_timeout_handle = window.setTimeout(function(){
					jQuery(document).trigger('close.facebox');
				}, 3000);
			});
		},
		'&s=' + flashvars.mtkey + '&is_emcpt=' + is_emcpt, 
		true, 
		{
			'exuids':	fs.join(','),
			'puid':		p_user.puid,
			'uid':		p_user.uid
		}
	);
}

function showContain(name, css, fn, p, isXFBML, postdata) {
	log('showContain', [name, css, fn, p, isXFBML, postdata]);
	if ('undefined' == typeof (p)) {
		p = '';
	}
	if ('undefined' == typeof (css)) {
		css = '';
	}
	if ('undefined' == typeof (fn) || fn == '') {
		fn = function() {
		};
	}
	if ('undefined' == typeof (isXFBML)) {
		isXFBML = false;
	}
	
	if ('object' != typeof (postdata)) {
		postdata = {};
	}
	
	var url = 'action.php?cmd=' + name + p;
	
	jQuery.post(url, postdata, function(data){
		jQuery(document).bind("reveal.facebox", function (event, message1, message2) {
			jQuery(document).unbind("reveal.facebox");

			FBParse(document.getElementById('facebox'), function(){
				jQuery('#facebox').css('left', jQuery(window).width() / 2 - (jQuery('#facebox .popup').width() / 2));
				if(jQuery('#wrapper').height() < jQuery('#facebox').height()) jQuery('#wrapper').css('height', jQuery('#facebox').height() + 100);
			});
			
			jQuery('#facebox').css('left', jQuery(window).width() / 2 - (jQuery('#facebox .popup').width() / 2));
			if(jQuery('#wrapper').height() < jQuery('#facebox').height()) jQuery('#wrapper').css('height', jQuery('#facebox').height() + 100);
			fn();
		});
		jQuery.facebox(data);
	});
}

function FBParse(obj, method) {
	if(typeof(method) != 'function') {
		method = function() {
			
		};
	}
	if (1) { // fbloaded
		FB.XFBML.parse(obj, method);
	}
}

function log( func, param ) {
	if(typeof(console) != 'undefined' && param != null ) {
		str = func + ": =====================================\n";
		switch(typeof(param)) {
			case 'boolean':
			case 'string':
				str = str + param;
				break;
			case 'object':
				for(var k in param) {
					str = str + " k = " + k + " v = " + param[k] + "\n";  
				}
				break;
		}
		
		console.log(str);
	}
}


function FlsO(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	} else if (navigator.appName.indexOf("Microsoft") == -1) {
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
	} else {
		return document.getElementById(movieName);
	}
}

//重写某某方法	facebox补丁
jQuery.extend(jQuery.facebox, {
	reveal: function(data, klass) {
	jQuery(document).trigger('beforeReveal.facebox');
		if (klass) jQuery('#facebox .content').addClass(klass);
		jQuery('#facebox .content')[0].innerHTML = data;
		jQuery('#facebox .loading').remove();
		jQuery('#facebox .body').children().fadeIn('normal');
		jQuery('#facebox').css('left', jQuery(window).width() / 2 - (jQuery('#facebox .popup').width() / 2));
		jQuery(document).trigger('reveal.facebox').trigger('afterReveal.facebox');
	}
	,
	settings: {
		opacity      : null,
		overlay      : false,
		loadingImage : img_url + 'fansclose.png',
		closeImage   : img_url + 'facebox/closelabel.png',
		imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
		faceboxHtml  : '\
 <div id="facebox" style="display:none;"> \
   <div class="popup"> \
     <div class="content"> \
     </div> \
   </div> \
 </div>'
 }
});

